<template>
  <view class="tabs-box">
    <u-tabs :list="data.list" v-model:current="data.current" lineWidth="82" lineHeight="3" lineColor="#f87610"
      :scrollable="false" @change="handleChage"></u-tabs>
  </view>
  <block v-if="data.current == 0">
    <block v-for="(item,index) in list" :key="item.id">
      <house-item :item="item" customStyle="background:#fff;margin:20rpx;" :imageWidth="234" imageHeight="192">
        <template #right>
          <view class="u-flex-between u-flex-column u-flex-fill">
            <view class="house-name">
              {{item.title}}
            </view>
            <view class="house-desc" v-if="item.description">“{{item.description}}”</view>
            <view class="house-info">“{{item.space}}㎡ | {{item.house_type_text}}”</view>
            <view class="house-price u-flex-y-center u-flex-between">
              <text>市场价：{{item.market_price}}万</text>
              <text>优惠价：{{item.price}}万</text>
            </view>
          </view>
        </template>
      </house-item>
    </block>
  </block>
  <block v-else>
    <view class="u-flex-y-center u-flex-wrap u-flex-between u-p-l-20 u-p-r-20">
      <block v-for="item in list" :key="item.id">
        <video-item :item="item"></video-item>
      </block>
    </view>
  </block>
</template>

<script setup>
  import houseItem from '@/components/house-item/house-item.vue';
  import videoItem from '@/components/video-item/video-item.vue';
  import { computed, onMounted, ref } from "vue"
  import { onReachBottom } from '@dcloudio/uni-app'
  import { collect_lst } from '../../config/api';
  const params = ref({
    page: 1,
    limit: 15,
    type: computed(() => data.value.current + 1)
  })
  const list = ref([])
  const data = ref({
    list: [{
      name: '房产信息'
    }, {
      name: '视频'
    }],
    current: 0
  })
  onMounted(() => {
    _collect_lst()
  })
  onReachBottom(() => {
    params.value.page++
    _collect_lst()
  })
  const handleChage = () => {
    params.value.page = 1
    _collect_lst()
  }
  const _collect_lst = () => {
    collect_lst(params.value).then(res => {
      if (params.value.page == 1) list.value = res.data
      else list.value = list.value.concat(res.data)
    })
  }
</script>

<style lang="scss" scoped>
  .tabs-box {
    position: sticky;
    top: 0;
    background: #fff;
  }

  .house-name {
    font-size: 26rpx;
    color: #333;
    font-weight: 800;
  }

  .house-info {
    font-size: 24rpx;
    font-weight: 500;
    color: #666;
  }

  .house-desc {
    font-size: 22rpx;
    color: #E47117;
  }

  .house-price {
    color: #DF0F0F;
    font-weight: 800;
    font-size: 24rpx;
  }
</style>